import os

import dotenv
import requests
import json
# from langchain_community.tools.openai_dalle_image_generation import OpenAIDALLEImageGenerationTool
# from langchain_community.utilities.dalle_image_generator import DallEAPIWrapper
# from langchain_openai import ChatOpenAI

dotenv.load_dotenv()

url = "https://qianfan.baidubce.com/v2/images/generations"

payload = json.dumps({
    "prompt": "生成哪吒在和敖丙对决的图片",
    "model": "irag-1.0"
}, ensure_ascii=False)

gaode_api_key = os.getenv("QIANFAN_API_KEY")

headers = {
    'Content-Type': 'application/json',
    'Authorization': f'Bearer {gaode_api_key}'
}

response = requests.request("POST", url, headers=headers, data=payload.encode("utf-8"))

print(response.text)

# dalle = OpenAIDALLEImageGenerationTool(api_wrapper=DallEAPIWrapper(model="dall-e-3"))
#
# llm = ChatOpenAI(model="gpt-4o")
# llm_with_tools = llm.bind_tools([dalle], tool_choice="openai_dalle")
#
# chain = llm_with_tools | (lambda msg: msg.tool_calls[0]["args"]) | dalle
#
# print(chain.invoke("帮我绘制一张老爷爷爬山的图片"))